import groovy.mock.interceptor.MockFor
import javax.swing.JPanel
import net.yiny.scrummer.ui.storyboard.PhasePanelBuilder
import net.yiny.scrummer.ui.storyboard.PhaseStripBuilder

scenario 'basic creation of a builder', {
    when 'we create the builder object', {
        builder = new PhasePanelBuilder()
    }
    then 'there are no errors', {}
}

scenario 'we should be able to initialise a phase panel builder with no child builder', {
    when 'we initialise a builder that has no child builders', {
        builder = new PhasePanelBuilder()
        panel = builder.initialise()
    }
    then 'the resulting JPanel should not be null', {
        panel.shouldNotBe null
        panel.shouldBeA JPanel
    }
}

scenario 'initialising a phase panel builder should produce a panel with the resulting panels of the children', {
    given 'two phase strip builders as children', {
        mockChildren = (1..3).collect {new MockFor(PhaseStripBuilder)}
        panels = mockChildren.collect {new JPanel()}
        mockChildren.size.times {idx ->
            mockChildren[idx].demand.initialise() {panels[idx]}
        }
        children = mockChildren.collect {it.proxyInstance()}
    }
    when 'we initialise the builder', {
        builder = new PhasePanelBuilder(children: children)
        panel = builder.initialise()
    }
    then 'the resulting panel is correct', {
        panel.shouldNotBe null
        panel.shouldBeA JPanel
    }
    and 'the child builder have been initialised', {
        mockChildren.size.times {
            mockChildren[it].verify children[it]
        }
    }
    and 'the returned panel contains the panels from the child builders', {
        panel.components.shouldBeEqualTo panels
    }
}
